import ch.sfug.events.EventDispatcher;
/**
 * @author loop
 */
class ch.sfug.net.loader.AbstractLoader extends EventDispatcher {

	private var _url:String;
	private var _preventCacheing:Boolean;

	/**
	 * creates a loader that stores the url to load from
	 * @param theUrl
	 * @param noCache if true the loaded url will contain a random number to prevent caching. default is false.
	 */
	public function AbstractLoader( theUrl:String , noCache:Boolean ) {
		url = theUrl;
		preventCacheing = noCache;
	}

	/**
	 * sets the url to load from
	 */
	public function set url( u:String ):Void {
		if( u != undefined && u.length > 0 ) {
			_url = u;
		}
	}

	/**
	 * returns the url
	 */
	public function get url(  ):String {
		if( _preventCacheing ) {
			var rand:String = Math.floor( Math.random() * 99999 ).toString();
			return ( _url.indexOf("?") != -1 ) ? ( _url + "&nocache=" + rand ) : ( _url + "?nocache=" + rand );
		} else {
			return _url;
		}
	}
	
	public function set preventCacheing( b:Boolean ):Void {
		if( b != undefined ) {
			_preventCacheing = b;
		}
		if( _preventCacheing == undefined ) {
			_preventCacheing = false;
		}
	}
	
	public function get preventCacheing():Boolean {
		return _preventCacheing;
	}

	/**
	 * ABSTRACT
	 * starts the load progress
	 */
	public function load( theUrl:String ):Void {
		// abstract
	}
	
	/**
	 * ABSTRACT
	 * stops the load
	 */
	public function stop(  ):Void {
        // abstract
	}
	
	/**
	 * ABSTRACT
	 * returns the result of the load
	 */
	public function getResult(  ):Object {
		return null;
	}

}